#include "cv_utils.h"

#include <opencv2/opencv.hpp>
#include "base64.h"

//imgType 包括png bmp jpg jpeg等opencv能够进行编码解码的文件
std::string Mat2Base64(const cv::Mat &image, std::string imgType)
{
    //Mat转base64
    std::vector<uchar> buf;
    cv::imencode(imgType, image, buf);
    //uchar *enc_msg = reinterpret_cast<unsigned char*>(buf.data());
    std::string img_data = base64_encode(buf.data(), buf.size(), false);
    return img_data;
}

cv::Mat Base642Mat(std::string &base64_data)
{
    cv::Mat img;
    std::string s_mat;
    s_mat = base64_decode(base64_data.data(), false);
    std::vector<char> base64_img(s_mat.begin(), s_mat.end());
    img = cv::imdecode(base64_img, cv::IMREAD_COLOR); //CV::IMREAD_UNCHANGED
    return img;
}